﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Staff_insertTeacherData : System.Web.UI.Page
{
    String OWNER = "SLP2";
    String FROM_MAIL = "qooliliyahoo.com.tw@gmail.com";
    String BLANK = " ";
    String DOUBLE_TAB = "\n\n";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session.Clear();
        }
    }
    protected void CreateUserWizard1_CreatedUser1(object sender, EventArgs e)
    {
        Roles.AddUserToRole(CreateUserWizard1.UserName, "teacher");

        Session["id"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
        Session["email"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
        Session["name"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox1")).Text;
        Session["lab"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox2")).Text;
        Session["degree"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox3")).Text;
        Session["phone"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox4")).Text;
        Session["cellphone"] = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox5")).Text;

        SqlDataSource1.Insert();
        if (!String.IsNullOrEmpty(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox4")).Text))
        {
            SqlDataSource2.Insert();
        }
        if (!String.IsNullOrEmpty(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBox5")).Text))
        {
            SqlDataSource3.Insert();
        }
        GridView1.DataBind();

        MailWebService.Mail mail = new MailWebService.Mail();

        mail.sender = FROM_MAIL;
        mail.receiver = CreateUserWizard1.Email.ToString();
        mail.subject = "學生歷程系統_帳號密碼" + BLANK + OWNER;
        mail.message = "這是您在學生歷程系 相關資訊" + BLANK + "請熟記您的帳號與密碼" + BLANK + "如遺忘請至忘記密碼查詢" + DOUBLE_TAB
                        + "您的帳號" + BLANK + CreateUserWizard1.UserName.ToString() + DOUBLE_TAB
                        + "您的密碼" + BLANK + CreateUserWizard1.Password.ToString();

        MailWebService.WebService mailWebService = new MailWebService.WebService();
        mailWebService.sendMail(mail);

        Session.Clear();
    }
}